package com.haotunet.app.goldtreasure.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.haotunet.app.goldtreasure.R;
import com.haotunet.app.goldtreasure.model.BankInfo;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/* *
 * Created by Administrator on 2017/5/5.
 */

public class BankListAdapter extends HolderAdapter<BankInfo, BankListAdapter.ViewHolder> {

    private OnItemClickListener mListener;

    public interface OnItemClickListener {
        void onItemClick(BankInfo info);
    }

    public BankListAdapter(Context context, List<BankInfo> listData) {
        super(context, listData);
    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, BankInfo bankInfo, int position) {
        return inflate(R.layout.item_support_bank);
    }

    @Override
    public ViewHolder buildHolder(View convertView, BankInfo bankInfo, int position) {
        ViewHolder holder = new ViewHolder(convertView);
        return holder;
    }

    @Override
    public void bindViewDatas(View convertView, final ViewHolder holder, final BankInfo bankInfo, int position) {
        holder.tvBankName.setText(bankInfo.getBankName());
        holder.tvQuota.setText(bankInfo.getBankDetail());
        holder.tvExtra.setText(bankInfo.getExpireTime());
        Glide.with(context).load(bankInfo.getBankLogo()).into(holder.ivBankLogo);
        if ("0".equals(bankInfo.getStatusType())) {
            convertView.setEnabled(true);
            holder.tvBankName.setTextColor(context.getResources().getColor(R.color.color_black1));
            holder.tvQuota.setTextColor(context.getResources().getColor(R.color.color_black1));
            holder.tvExtra.setVisibility(View.GONE);
            holder.ivBankLogo.setColorFilter(0);
        } else {
            convertView.setEnabled(false);
            holder.tvBankName.setTextColor(context.getResources().getColor(R.color.shallow_gray));
            holder.tvQuota.setTextColor(context.getResources().getColor(R.color.shallow_gray));
            holder.tvExtra.setVisibility(View.VISIBLE);
            holder.tvExtra.setText(bankInfo.getMaintainTime());
            holder.ivBankLogo.setColorFilter(Color.rgb(155, 155, 155));
        }
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onItemClick(bankInfo);
            }
        });
    }


    static class ViewHolder {
        @InjectView(R.id.iv_bank_logo)
        ImageView ivBankLogo;
        @InjectView(R.id.tv_bank_name)
        TextView tvBankName;
        @InjectView(R.id.tv_extra)
        TextView tvExtra;
        @InjectView(R.id.tv_Quota)
        TextView tvQuota;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mListener = listener;
    }
}
